package com.smh.aiagent.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.reactive.function.client.ClientRequest;
import org.springframework.web.reactive.function.client.WebClient;

/**
 * @author shiminghui
 * @date 2025/6/7 11:25
 * @description: 为了对MCP的工具调用添加参数，这里添加一个配置类
 */
@Configuration
public class WebClientConfig {

    @Value("${custom.pexels.api-key}")
    private String pexelsApiKey;


    /**
     * 未生效
     *
     * @return
     */
    @Bean
    public WebClient webClient() {
        return WebClient.builder()
                .filter((request, next) -> {
                    ClientRequest newRequest = ClientRequest.from(request)
                            .header("IMAGE_SEARCH_API_KEY", pexelsApiKey)
                            .build();
                    return next.exchange(newRequest);
                })
                .build();
    }

}
